package com.app;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

@SpringBootApplication
@MapperScan("com.app.mapper")  //配置mapper扫描
public class Application extends SpringBootServletInitializer implements CommandLineRunner {


    protected static Log log = LogFactory.getLog(Application.class);
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }
    public static void main(String[] args)  throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(Application.class, args);
        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path")==null? "":env.getProperty("server.servlet.context-path");
        log.info("\n----------------------------------------------------------\n" +
                "Application service is running! Access URLs:\n" +
                "Swagger文档: \thttp://" + ip + ":" + port + path + "/swagger-ui.html\n" +
                "----------------------------------------------------------");
    }
    /**
     * springboot运行后此方法首先被调用<br/>
     * 实现CommandLineRunner抽象类中的run方法
     */
    @Override
    public void run(String... args) throws Exception {
        System.out.println("-------------application service started successfully----------------");
    }
}